package com.senac.parser;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import com.senac.model.Professor;
import com.senac.model.Titulacao;

public class ProfessorParser extends Parser<Professor> {
	

	public ProfessorParser(ResultSet rs) {
		super(rs);
	}

	
	@Override
	public Professor parse() throws SQLException {
		
		Professor professor = new Professor();
		
		ResultSetMetaData md = getRs().getMetaData();
		
		for (int i = 1; i <= md.getColumnCount(); i++) {
			String columnName = md.getColumnName(i).toLowerCase();
			
			switch (columnName) {
			case "id":
				professor.setId(getRs().getInt(columnName));
				break;
			case "nome":
				professor.setNome(getRs().getString(columnName));
				break;
			case "titulacao":
				professor.setTitulacao(Titulacao.values()[getRs().getInt("titulacao")]);
				break;
			case "carga_horaria":
				professor.setCargaHoraria(getRs().getInt(columnName));
				break;
				
			default:
				break;
			}
		}
		
		return professor;
		
	}

}
